Out: Monday, February 8, 2016
Due: Monday, February 15, 2016 at 5pm EST
Corrected: Tuesday, February 9 (to correct references to dx and dy, which should have been vx and vy)
The goal of this problem set is to help you design functions that deal with lists, and with the Iterative Design Recipe.
You must use the HtDP Beginning Student Language to solve the problems.
For these problems, download a copy of extras.rkt and put it in the folder with your solutions. Then import this library by including the line
(require "extras.rkt")at the top of your file with the other requires. Then, for each problem, put in lines that say
(provide function)for each deliverable function, as you have done on previous problem sets. This will allow our testing framework to import your file and do automated testing on it.
Remember that you must follow the design recipe. Your deliverables include the data definitions (including interpretation and templates), contract and purpose header, code, and tests. Be sure to sync your work and fill out a Work Session Report at the end of every work session. Use the Work Session Report for PS04.
Note: For all universe programs, you may assume the mouse is never dragged or moved outside of the canvas. Once the mouse enters the canvas, if the mouse ever leaves the canvas, then the behavior of your system is unspecified.
"right"
)
increases the vx component of all selected goofballs
by 1 cm per tick.
The left arrow key ("left"
)
decreases the vx component of all selected goofballs
by 1 cm per tick.
The down arrow key ("down"
)
increases the vy component of all selected goofballs
by 1 cm per tick.
The up arrow key ("up"
)
decreases the vy component of all selected goofballs
by 1 cm per tick.
Hint: One tick's worth of motion for a goofball moving at velocity (vx,vy) can be calculated by computing its horizontal movements independently of its vertical movements. That allows the net effect of a perfect bounce to be calculated using integer arithmetic.
The screensaver is paused at first, as in Problem Set 03. The situation shown in the following image was created by hitting the "n" key four times to create new goofballs, selecting the leftmost goofball and hitting the "left" and "up" arrow keys ten times each, and selecting the second goofball from the left while hitting the "right" and "down" arrow keys ten times each:
Unpausing the world shown above results in this motion:
You are to deliver a file named screensaver-3.rkt that
provides the functions listed below.
Note that screensaver
, initial-world
,
world-after-tick
, world-after-key-event
, and
world-after-mouse-event
implicitly refer to the
specification above, so they behave differently in screensaver-3
than in screensaver-2 even though their contracts and purpose
statements read the same as before.
;;; screensaver : PosReal -> WorldState ;;; GIVEN: the speed of the screensaver, in seconds per tick ;;; (so larger numbers run slower) ;;; EFFECT: runs the screensaver, starting with the initial state as ;;; specified above ;;; RETURNS: the final state of the world ;;; EXAMPLES: ;;; (screensaver 1) runs the screensaver at normal speed ;;; (screensaver 1/4) runs at a faster than normal speed ;;; initial-world : Any -> WorldState ;;; GIVEN: any value (ignored) ;;; RETURNS: the initial world specified for the screensaver ;;; EXAMPLE: (initial-world -174) ;;; world-after-tick : WorldState -> WorldState ;;; GIVEN: any WorldState that's possible for the screensaver ;;; RETURNS: the WorldState that should follow the given WorldState ;;; after a tick ;;; world-after-key-event : WorldState KeyEvent -> WorldState ;;; GIVEN: a WorldState and a KeyEvent ;;; RETURNS: the WorldState that should follow the given WorldState ;;; after the given KeyEvent ;;; world-after-mouse-event ;;; : WorldState Int Int MouseEvent -> WorldState ;;; ;;; GIVEN: A World, the x- and y-coordinates of a mouse event, and the ;;; mouse event ;;; RETURNS: the world that should follow the given world after the given ;;; mouse event. ;;; world-goofballs : WorldState -> ListOfGoofball ;;; GIVEN: a WorldState ;;; RETURNS: a list of the goofballs present in the WorldState ;;; (without goofballs that have been deleted using the "d" key) ;;; world-paused? : WorldState -> Boolean ;;; GIVEN: a WorldState ;;; RETURNS: true iff the WorldState is paused ;;; goofball-selected? : Goofball -> Boolean ;;; GIVEN: a Goofball ;;; RETURNS: true iff the given Goofball is selected ;;; goofball-radius : Goofball -> Integer ;;; GIVEN: a Goofball ;;; RETURNS: its radius, in cm ;;; goofball-x : Goofball -> Integer ;;; goofball-y : Goofball -> Integer ;;; GIVEN: a Goofball ;;; RETURNS: its corresponding x or y coordinate, in cm ;;; goofball-vx : Goofball -> Integer ;;; goofball-vy : Goofball -> Integer ;;; GIVEN: a Goofball ;;; RETURNS: its corresponding vx or vy velocity component, in cm/tick
You are to deliver a file named screensaver-4.rkt that
adds this behavior to the screensaver
and
world-after-tick
functions.
You should provide
the same thirteen functions
you provided for screensaver-3.
Last modified: Tue Feb 09 2016